package net.sf.odinms.client.messages.commands;


import net.sf.odinms.client.messages.Command;
import net.sf.odinms.client.messages.CommandDefinition;
import net.sf.odinms.client.messages.IllegalCommandSyntaxException;
import net.sf.odinms.client.messages.MessageCallback;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.client.messages.ServernoticeMapleClientMessageCallback;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.SavedLocationType;
import net.sf.odinms.tools.MaplePacketCreator;

public class PlayerCommands implements Command {

    @Override
    
    public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception,IllegalCommandSyntaxException {
        MapleCharacter player = c.getPlayer();
        if (splitted[0].equals("@射手")) {
            if ((c.getPlayer().getMapId() != 100000000)){
                c.getSession().write(MaplePacketCreator.enableActions());
                MapleMap to;
                to = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(100000000);
                c.getPlayer().changeMap(to);
                new ServernoticeMapleClientMessageCallback(5, c).dropMessage("你来到了射手村！");
            } else {
                new ServernoticeMapleClientMessageCallback(5, c).dropMessage("你已经在射手村了，还想去哪里？.");
                c.getSession().write(MaplePacketCreator.enableActions());
            }
        } else if (splitted[0].equalsIgnoreCase("@经验")) {
            player.setExp(0);
            player.updateSingleStat(MapleStat.EXP, player.getExp());
        } else if (splitted[0].equals("@力量")) {
            int up= -1;
            up = Integer.parseInt(splitted[1]);
            if (up == -1)
            {
                c.getPlayer().黄字公告("输入参数有误！");
            } else if ((player.getRemainingAp() < up || player.getRemainingAp() < 0) && up > 0) {
                    c.getPlayer().黄字公告("你没有足够的力量点！！");
                } else if ((player.getRemainingAp() > 0) && up > 0) {
                    player.setStr(player.getStr() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.STR, player.getStr());
                } else {
                c.getPlayer().黄字公告("你的输入有误！！");
                }
            } else if (splitted[0].equals("@智力")) {
                int up = -1;
                up = Integer.parseInt(splitted[1]);
                if (up == -1)
                {
                    c.getPlayer().黄字公告("输入参数有误！");
                }else
                if ((player.getRemainingAp() < up || player.getRemainingAp() < 0) && up > 0) {
                    c.getPlayer().黄字公告("你没有足够的智力点！！");
                } else if ((player.getRemainingAp() > 0) && up > 0) {
                    player.setInt(player.getInt() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.INT, player.getInt());
                } else {
                    c.getPlayer().黄字公告("你的输入有误！！");
                }
            } else if (splitted[0].equals("@敏捷")) {
                int up = -1;
                up = Integer.parseInt(splitted[1]);
                if (up == -1)
                {
                    c.getPlayer().黄字公告("输入参数有误！");
                }else
                if ((player.getRemainingAp() < up || player.getRemainingAp() < 0) && up > 0) {
                    c.getPlayer().黄字公告("你没有足够的敏捷点！！");
                } else if ((player.getRemainingAp() > 0) && up > 0) {
                    player.setDex(player.getDex() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.DEX, player.getDex());
                } else {
                    c.getPlayer().黄字公告("你的输入有误！！");
                }
            }else if (splitted[0].equals("@运气")) {
                int up = -1;
                up = Integer.parseInt(splitted[1]);
                if (up == -1)
                {
                    c.getPlayer().黄字公告("输入参数有误！");
                }else if ((player.getRemainingAp() < up || player.getRemainingAp() < 0) && up > 0) {
                    c.getPlayer().黄字公告("你没有足够的运气点！！");
                } else if ((player.getRemainingAp() > 0) && up > 0) {
                    player.setLuk(player.getLuk() + up);
                    player.setRemainingAp(player.getRemainingAp() - up);
                    player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                    player.updateSingleStat(MapleStat.LUK, player.getLuk());
                } else {
                    c.getPlayer().黄字公告("你的输入有误！");
                }
        } else if (splitted[0].equalsIgnoreCase("@帮助")) {
                c.getPlayer().黄字公告("=====================");
                c.getPlayer().黄字公告("真正枫之谷 - 帮助命令：");
                c.getPlayer().黄字公告("=====================");
                c.getPlayer().黄字公告("@射手 传送到射手村!");
                c.getPlayer().黄字公告("@自由 传送到自由市场!");
                c.getPlayer().黄字公告("@经验 经验清零!");
                c.getPlayer().黄字公告("@力量 <数量> 快速加力量属性点!");
                c.getPlayer().黄字公告("@敏捷 <数量> 快速加敏捷属性点!");
                c.getPlayer().黄字公告("@智力 <数量> 快速加智力属性点!");
                c.getPlayer().黄字公告("@运气 <数量> 快速加运气属性点!");
        } else if (splitted[0].equals("@自由")) {
            if ((c.getPlayer().getMapId() < 910000000) || (c.getPlayer().getMapId() > 910000022)){
               c.getSession().write(MaplePacketCreator.enableActions());
                 MapleMap to;
                 MaplePortal pto;
                to = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(910000000);
                c.getPlayer().saveLocation(SavedLocationType.FREE_MARKET);//取消
                pto = to.getPortal("out00");
                c.getPlayer().changeMap(to, pto);
                new ServernoticeMapleClientMessageCallback(5, c).dropMessage("你已经回到了自由市场！");
             } else {
              new ServernoticeMapleClientMessageCallback(5, c).dropMessage("你已经在自由市场了，还想去哪里？.");
               c.getSession().write(MaplePacketCreator.enableActions());
             }
        }
	}

	@Override
	public CommandDefinition[] getDefinition() {
		return new CommandDefinition[] {
                    new CommandDefinition("经验", "", "", 0),
                    new CommandDefinition("射手", "", "", 0),
                    new CommandDefinition("自由", "", "", 0),
                    new CommandDefinition("力量", "", "", 0),
                    new CommandDefinition("敏捷", "", "", 0),
                    new CommandDefinition("智力", "", "", 0),
                    new CommandDefinition("运气", "", "", 0),
                    new CommandDefinition("帮助", "", "", 0),

		};
	}

    }